import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCStudent {
    private static int id;
    private static String name;

    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/test1?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("1115");

        Connection connection = dataSource.getConnection();

        String sql = "insert into student values(?,?)";
        
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        
        preparedStatement.setInt(1,8 );
        preparedStatement.setString(2,"张三");
        preparedStatement.setInt(1,9);
        preparedStatement.setString(2,"李四");
        int n = preparedStatement.executeUpdate();
        System.out.println("n= " + n);
        
        preparedStatement.close();
        connection.close();
    }
}
